package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.QuestionCategory;
import com.tancire.question.service.IQuestionCategoryService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 问题分类Controller
 *
 * @author chenchao
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/question/QuestionCategory")
public class QuestionCategoryController extends BaseController {
    @Resource
    private IQuestionCategoryService questionCategoryService;

    /**
     * 查询问题分类列表
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionCategory questionCategory) {
        startPage();
        List<QuestionCategory> list = questionCategoryService.selectQuestionCategoryList(questionCategory);
        return getDataTable(list);
    }

    /**
     * 查询问题分类列表(全查)
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(QuestionCategory questionCategory) {
        List<QuestionCategory> list = questionCategoryService.selectQuestionCategoryList(questionCategory);
        return AjaxResult.success("查询成功", list);
    }

    /**
     * 导出问题分类列表
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:export')")
    @Log(title = "问题分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionCategory questionCategory) {
        List<QuestionCategory> list = questionCategoryService.selectQuestionCategoryList(questionCategory);
        ExcelUtil<QuestionCategory> util = new ExcelUtil<QuestionCategory>(QuestionCategory.class);
        util.exportExcel(response, list, "问题分类数据");
    }

    /**
     * 获取问题分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId) {
        return AjaxResult.success(questionCategoryService.selectQuestionCategoryByCategoryId(categoryId));
    }

    /**
     * 新增问题分类
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:add')")
    @Log(title = "问题分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionCategory questionCategory) {
        return toAjax(questionCategoryService.insertQuestionCategory(questionCategory));
    }

    /**
     * 修改问题分类
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:edit')")
    @Log(title = "问题分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionCategory questionCategory) {
        return toAjax(questionCategoryService.updateQuestionCategory(questionCategory));
    }

    /**
     * 删除问题分类
     */
    @PreAuthorize("@ss.hasPermi('question:QuestionCategory:remove')")
    @Log(title = "问题分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(questionCategoryService.deleteQuestionCategoryByCategoryIds(categoryIds));
    }
}
